package com.mgy.db.common.query;

import com.mgy.db.TableRouter;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.io.Serializable;

/**
 * 基类
 *
 * @author maguoyong
 * @since 2020-01-28 21:24:28
 */
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
public abstract class BaseQuery extends TableRouter implements Serializable {

    private Integer pageSize;
    private Integer pageNo;
    private Integer startIndex;
    private Integer toIndex;

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getPageNo() {
        return pageNo;
    }

    public void setPageNo(Integer pageNo) {
        this.pageNo = pageNo;
    }

    public int getStartIndex() {
        return (pageNo == null || pageSize == null) ? 0 : (pageNo - 1) * pageSize;
    }

    public void setStartIndex(int startIndex) {
        this.startIndex = startIndex;
    }

    public int getToIndex() {
        return (pageNo == null || pageSize == null) ? 0 : pageNo * pageSize - 1;
    }

    public void setToIndex(int toIndex) {
        this.toIndex = toIndex;
    }
}